package com.spring.framework.ioc.xml;

import com.spring.framework.model.annotation.COOmponentName;
import com.spring.framework.model.annotation.ComponentName;
import com.spring.framework.model.annotation.ComponentOne;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author xuweizhi
 * @since 2020/12/09 17:57
 */
public class AnnotationTest {

	@Test
	public void testIoc() {
		ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("config/annotation/spring-ioc.xml");
		System.out.println(ac.getBean("componentOne", ComponentOne.class));
		System.out.println(ac.getBean("componentOne", ComponentOne.class));
		System.out.println(ac.getBean("componentTwo", ComponentOne.ComponentTwo.class));
		System.out.println(ac.getBean("componentTwo", ComponentOne.ComponentTwo.class));
		System.out.println(ac.getBean("componentThree", ComponentOne.ComponentThree.class));
		System.out.println(ac.getBean("componentThree", ComponentOne.ComponentThree.class));
	}

	@Test
	public void annoName() {
		ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("config/annotation/spring-ioc.xml");
		System.out.println("--------------------");
		//普通外部类，默认bean名称生成器将返回小写的非限定类名。
		System.out.println(ac.getBean("componentName", ComponentName.class));
		//普通外部类，如果类名有多个字符并且前两个字符都是大写时，将直接返回简单类名。
		System.out.println(ac.getBean("COOmponentName", COOmponentName.class));
		//普通内部类，默认bean名称生成器将返回全限定外部类名$内部类名。
		System.out.println(ac.getBean("com.spring.framework.model.annotation.ComponentName$ComponentNameTwo", ComponentName.ComponentNameTwo.class));
		//静态内部类，默认bean名称生成器将返回小写的非限定外部类名.内部类名。
		System.out.println(ac.getBean("componentName.ComponentNameThree", ComponentName.ComponentNameThree.class));
	}
}
